<#include "/include/tag.ftl">
<#import "/macro/articleTemplate.ftl" as art>
<html lang="en">
<head>
	<title>Share Advance</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<#include "/include/common.ftl">
	<script src="${ctx}/static/lib/xheditor/xheditor-1.2.2.min.js"></script>
	<script src="${ctx}/static/lib/xheditor/xheditor_lang/zh-cn.js"></script>
</head>

<body class="home">
	<#include "/template/header.ftl">
	<div id="content-wrapper">
		<header class="secondary head"></header>
		<!-- container -->
		<div class="container">
		
			<ol class="breadcrumb">
				<li><a href="${ctx}/index">首页</a></li>
				<li class="active">写文章</li>
			</ol>
		
			<div class="row">
				<div class="col-sm-9 maincontent">
					<header class="page-header">
						<h1 class="page-title">写文章</h1>
					</header>
					<form id="article_form" enctype="multipart/form-data" class="form-horizontal">
						<div class="form-group">
							<label>文章标题<span class="text-danger">*</span></label>
							<input name="title" type="text" class="form-control">
						</div>
						<hr>
						<div class="form-group">
							<label>文章内容<span class="text-danger">*</span></label>
							<textarea id="article_txt" name="txt" rows="20" cols="80" style="width: 100%">
								
							</textarea>
						</div>
						<div class="form-group">
							<label>文章摘要（默认文章开头200个文字）</label>
							<textarea id="articl_desc" name="description" class="form-control" cols="80" rows="4" style="width:100%;" ></textarea>
						</div>
						<div class="form-group">
	                        <input class="btn btn-primary" type="submit" id="send_btn"  value="发表文章" />
	                    </div>
                    <form>
				</div>
				
				<aside class="col-sm-3 sidebar sidebar-right">
				</aside>
			</div>
		</div>
	</div>
	<#include "/template/footer.ftl">
</body>
</html>
<script type="text/javascript">
	$(function(){
		//初始化xheditor
		$("#article_txt").xheditor({
			tools:'Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Removeformat,|,Align,List,Outdent,Indent,|,Link,Img,Emot,Table,|,Source,Fullscreen,About',
			skin:'nostyle',
			upImgUrl:'${ctx}/picture/uploadImg',
			upImgExt: 'jpg,jpeg,gif,png',
			html5Upload: false,
			onUpload:insertUpload
		});
		
		//文件上传回调
		function insertUpload(msg) {
			$("#article_txt").append(msg.toString());
		}
	});
	
	//验证表单
	$("#article_form").validate({
		rules:{
			title:{required:true,maxlength:40},
			desc:{maxlength:200}
		},
		submitHandler:function(form) {
			$("#send_btn").prop("disabled",true);
			$(form).ajaxSubmit({
				type : "POST",
				dataType : "JSON",
				url : "${ctx}/article/saveArticle",
				success : function(data) {
					if(data.success == true) {
						alert("文章保存成功！")
						window.location.href="${ctx}/article/getArticlesList";
					}else {
						alert(data.errorMessage);
					}
					$("#send_btn").prop("disabled",false);
				}
			});
		}
	});
	
	$("#article_form").on("click","#send_btn",function(){
		$("#article_form").submit();
	});
</script>

